from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-14 14:08:00.636584
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 14, May, 2021
Time: 14:08:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2413
Nobs: 291.000 HQIC: -48.9222
Log likelihood: 3558.20 FPE: 3.59581e-22
AIC: -49.3773 Det(Omega_mle): 2.65299e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.365528 0.112276 3.256 0.001
L1.Burgenland 0.071960 0.058454 1.231 0.218
L1.Kärnten -0.225389 0.052048 -4.330 0.000
L1.Niederösterreich 0.101676 0.124120 0.819 0.413
L1.Oberösterreich 0.231659 0.121023 1.914 0.056
L1.Salzburg 0.283441 0.066510 4.262 0.000
L1.Steiermark 0.112224 0.084967 1.321 0.187
L1.Tirol 0.124747 0.058975 2.115 0.034
L1.Vorarlberg -0.032678 0.054229 -0.603 0.547
L1.Wien -0.026323 0.107836 -0.244 0.807
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396470 0.129600 3.059 0.002
L1.Burgenland 0.004996 0.067474 0.074 0.941
L1.Kärnten 0.327274 0.060080 5.447 0.000
L1.Niederösterreich 0.116080 0.143272 0.810 0.418
L1.Oberösterreich -0.065331 0.139698 -0.468 0.640
L1.Salzburg 0.233592 0.076772 3.043 0.002
L1.Steiermark 0.094208 0.098077 0.961 0.337
L1.Tirol 0.133747 0.068075 1.965 0.049
L1.Vorarlberg 0.153624 0.062597 2.454 0.014
L1.Wien -0.386718 0.124476 -3.107 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.256654 0.057235 4.484 0.000
L1.Burgenland 0.107868 0.029798 3.620 0.000
L1.Kärnten -0.012883 0.026533 -0.486 0.627
L1.Niederösterreich 0.090004 0.063273 1.422 0.155
L1.Oberösterreich 0.283437 0.061694 4.594 0.000
L1.Salzburg 0.018496 0.033905 0.546 0.585
L1.Steiermark -0.000594 0.043314 -0.014 0.989
L1.Tirol 0.069059 0.030064 2.297 0.022
L1.Vorarlberg 0.077230 0.027644 2.794 0.005
L1.Wien 0.112535 0.054972 2.047 0.041
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187411 0.054574 3.434 0.001
L1.Burgenland 0.028337 0.028413 0.997 0.319
L1.Kärnten 0.009457 0.025299 0.374 0.709
L1.Niederösterreich 0.060433 0.060332 1.002 0.316
L1.Oberösterreich 0.399618 0.058826 6.793 0.000
L1.Salzburg 0.084812 0.032329 2.623 0.009
L1.Steiermark 0.131996 0.041300 3.196 0.001
L1.Tirol 0.049408 0.028666 1.724 0.085
L1.Vorarlberg 0.082902 0.026359 3.145 0.002
L1.Wien -0.035862 0.052416 -0.684 0.494
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.403609 0.107649 3.749 0.000
L1.Burgenland 0.104223 0.056046 1.860 0.063
L1.Kärnten 0.010404 0.049904 0.208 0.835
L1.Niederösterreich 0.042875 0.119006 0.360 0.719
L1.Oberösterreich 0.124429 0.116036 1.072 0.284
L1.Salzburg 0.063416 0.063769 0.994 0.320
L1.Steiermark 0.066826 0.081465 0.820 0.412
L1.Tirol 0.198171 0.056545 3.505 0.000
L1.Vorarlberg 0.040829 0.051995 0.785 0.432
L1.Wien -0.051130 0.103393 -0.495 0.621
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201737 0.084371 2.391 0.017
L1.Burgenland -0.010460 0.043926 -0.238 0.812
L1.Kärnten -0.005268 0.039113 -0.135 0.893
L1.Niederösterreich -0.007430 0.093272 -0.080 0.937
L1.Oberösterreich 0.423922 0.090945 4.661 0.000
L1.Salzburg 0.013171 0.049980 0.264 0.792
L1.Steiermark -0.028174 0.063849 -0.441 0.659
L1.Tirol 0.157366 0.044318 3.551 0.000
L1.Vorarlberg 0.059411 0.040751 1.458 0.145
L1.Wien 0.201072 0.081035 2.481 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196375 0.102572 1.915 0.056
L1.Burgenland 0.026420 0.053402 0.495 0.621
L1.Kärnten -0.072473 0.047550 -1.524 0.127
L1.Niederösterreich -0.031283 0.113393 -0.276 0.783
L1.Oberösterreich 0.007473 0.110564 0.068 0.946
L1.Salzburg 0.089940 0.060761 1.480 0.139
L1.Steiermark 0.313682 0.077623 4.041 0.000
L1.Tirol 0.456937 0.053878 8.481 0.000
L1.Vorarlberg 0.149152 0.049542 3.011 0.003
L1.Wien -0.134144 0.098516 -1.362 0.173
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199495 0.121732 1.639 0.101
L1.Burgenland 0.041955 0.063378 0.662 0.508
L1.Kärnten -0.073423 0.056432 -1.301 0.193
L1.Niederösterreich 0.114195 0.134574 0.849 0.396
L1.Oberösterreich 0.014253 0.131217 0.109 0.914
L1.Salzburg 0.194484 0.072112 2.697 0.007
L1.Steiermark 0.131079 0.092123 1.423 0.155
L1.Tirol 0.053370 0.063942 0.835 0.404
L1.Vorarlberg 0.108176 0.058797 1.840 0.066
L1.Wien 0.224063 0.116919 1.916 0.055
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.474544 0.068305 6.947 0.000
L1.Burgenland -0.010101 0.035562 -0.284 0.776
L1.Kärnten -0.018292 0.031665 -0.578 0.563
L1.Niederösterreich 0.109002 0.075511 1.444 0.149
L1.Oberösterreich 0.309691 0.073627 4.206 0.000
L1.Salzburg 0.026716 0.040462 0.660 0.509
L1.Steiermark -0.043524 0.051691 -0.842 0.400
L1.Tirol 0.078240 0.035879 2.181 0.029
L1.Vorarlberg 0.104530 0.032991 3.168 0.002
L1.Wien -0.029073 0.065604 -0.443 0.658
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.162381 0.084130 0.172651 0.225117 0.075913 0.084207 0.000965 0.172395
Kärnten 0.162381 1.000000 0.053949 0.216552 0.190298 -0.064017 0.180437 0.022600 0.311000
Niederösterreich 0.084130 0.053949 1.000000 0.239137 0.097436 0.314992 0.144236 0.027385 0.311849
Oberösterreich 0.172651 0.216552 0.239137 1.000000 0.307494 0.263473 0.104939 0.061766 0.147146
Salzburg 0.225117 0.190298 0.097436 0.307494 1.000000 0.155629 0.071460 0.091420 0.037841
Steiermark 0.075913 -0.064017 0.314992 0.263473 0.155629 1.000000 0.096910 0.101554 -0.094888
Tirol 0.084207 0.180437 0.144236 0.104939 0.071460 0.096910 1.000000 0.154922 0.158403
Vorarlberg 0.000965 0.022600 0.027385 0.061766 0.091420 0.101554 0.154922 1.000000 -0.011510
Wien 0.172395 0.311000 0.311849 0.147146 0.037841 -0.094888 0.158403 -0.011510 1.000000